﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DatabaseHelper;
using System.IO;
using SDK10kWrapper;
using System.Configuration;
using RS232;
using UI.Online.SubForms;

namespace UI.Online
{
    public partial class frmOnlineUI2
    {
        private void SetComPort(string portName, int baudRate, string format, string name)
        {
            if (!SurveyDataReader.IsOpen)
            {
                try
                {
                    SurveyDataReader.Port.PortName = portName;
                    SurveyDataReader.Port.BaudRate = baudRate;
                    SurveyDataReader.StringFormat = format;
                    SurveyDataReader.StringName = name;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

        private void SurveyDataReader_RS232DataReceived(object sender, RS232DataReceivedEventArgs e)
        {
            DataNow = new PData();
            DataNow = e.Data;
            SetText(DataNow);
        }

        private void SetText(PData pdt)
        {
            txtKP.Text = pdt.KP;
            txtEasting.Text = pdt.Easting;
            txtNorthing.Text = pdt.Northing;
            txtCP.Text = pdt.CP;
        }

        public void StartLoggingSurveyData(string recordID)
        {
            if (!SurveyDataReader.IsOpen)
            {
                SurveyDataReader.Open();
            }
            SurveyDataReader.StartLogging(recordID);
        }

        public void StopLoggingSurveyData()
        {
            SurveyDataReader.StopLogging();
        }

        public void ConnectToSurveyData()
        {
            SurveyDataReader.RS232DataReceived += new EventHandler<RS232DataReceivedEventArgs>(SurveyDataReader_RS232DataReceived);
            SurveyDataReader.Open();
        }

        public void DisconnectToSurveyData()
        {
            SurveyDataReader.Open();
        }
    }
}
